Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for label/fieldset in serializer #30

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

NicolasBadey
Copy link
Contributor

Important for easly create a kind of FormView from Form ressource in a SDK (outside of SF2)

render for exemple :

<form>
    <label for="form_name">custom label</label>
    <input type="text" id="form_name" name="form[name]" required="required"/>
    <textarea id="form_description" name="form[description]" required="required">Desc</textarea>
    <label for="form_gender">custom</label>
    <select name="form[gender]" required="required" id="form_gender">
        <option value="m">male</option>
        <option value="f">female</option>
    </select>
    <label for="form_genderRadio">label</label>
    <fieldset id="form_genderRadio">
        <label for="form_genderRadio_0">male</label>
        <input type="radio" id="form_genderRadio_0" value="m" name="form[genderRadio]" required="required"/>
        <label for="form_genderRadio_1">female</label>
        <input type="radio" id="form_genderRadio_1" value="f" name="form[genderRadio]" required="required"/>
    </fieldset>
    <input type="hidden" id="form_limit" name="form[limit]"/>
    <input type="email" id="form_towns_par" value="Paris" name="form[towns][par]" class="email-box"/>
    <input type="email" id="form_towns_lon" value="London" name="form[towns][lon]" class="email-box"/>
    <label for="form_public">label</label>
    <input type="checkbox" id="form_public" value="1" checked="1" name="form[public]"/>
</form>

@@ -42,6 +42,11 @@ protected function serializeBlock(\DOMElement $parentElement, FormView $view, $b
}
}

if ($variables['label'])
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CS issue

@NicolasBadey
Copy link
Contributor Author

hum, I have to translate label key if we want the same comportment than Sf2

@@ -42,6 +42,11 @@ protected function serializeBlock(\DOMElement $parentElement, FormView $view, $b
}
}

if (null === $variables['label'])
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow the PSR-2 CS.

@stof
Copy link

stof commented Feb 22, 2013

Are the choice values translated currently ?

@NicolasBadey
Copy link
Contributor Author

Not, it's label, I have to do

$parentElement->appendChild($labelElement);

$labelElement->setAttribute('for', $variables['id']);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line

@adrienbrault
Copy link
Contributor

What you do must follow the same logic as in the commented twig. See https://github.com/symfony/symfony/blob/2.1/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig (although it may have been updated a bit since I've written the class)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants